
package com.assistant.core.modules.sys.app.role;

import com.assistant.core.modules.sys.app.role.cmd.RoleInsertCmd;
import com.assistant.core.modules.sys.app.role.cmd.RoleUpdateCmd;
import com.assistant.core.modules.sys.domain.role.Role;
import com.assistant.core.modules.sys.domain.role.gateway.RoleGateway;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class RoleService {

    @Autowired
    private RoleGateway gateway;

    public Role get(Long id) {
        return gateway.getById(id);
    }

    public List<Role> list() {
        return gateway.findAll();
    }

    public void insert(RoleInsertCmd cmd) {
        Role role = new Role();
        BeanUtils.copyProperties(cmd, role);
        gateway.save(role);
    }

    public void update(RoleUpdateCmd cmd) {
        Role role = gateway.getById(cmd.getId());
        BeanUtils.copyProperties(cmd, role);
        gateway.save(role);
    }

    public void delete(Long id) {
        gateway.deleteById(id);
    }
}

